package com.css.spring.demo.controller;

import com.css.spring.demo.service.TestService;
import com.css.spring.demo.service.impl.TestServiceImpl;
import com.css.spring.formework.annotation.Autowired;
import com.css.spring.formework.annotation.Controller;
import com.css.spring.formework.annotation.RequestMapping;
import com.css.spring.formework.annotation.RequestParam;
import com.css.spring.formework.webmvc.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("test")
public class TestController {

    @Autowired
    private TestService testService;

    @RequestMapping("/sayHello")
    public ModelAndView testPrint(HttpServletRequest servletRequest,
                                  @RequestParam("name") String name) {

        Map<String, String[]> parameterMap = servletRequest.getParameterMap();
        for (Map.Entry<String, String[]> stringEntry : parameterMap.entrySet()) {
            System.out.println(Arrays.toString(stringEntry.getValue()));
        }

        testService.print();
        Map<String, Object> objectMap = new HashMap<String, Object>();
        objectMap.put("name", name);
        return new ModelAndView("index.html", objectMap);
    }
}
